package org.example.afree;

import java.util.List;
import java.util.Stack;
import java.util.stream.Collectors;

public class palindromic_number {
    public static void main(String[] args) {
        int i = 121;
//        String s = String.valueOf(i);
//        List<Character> collect = s.chars().mapToObj(c -> (char)c).collect(Collectors.toList());
//        for (Character c : collect) {
//            System.out.println(c);
//        }
        boolean palindrome = isPalindrome(i);
        System.out.println(palindrome);
    }

    public static boolean isPalindrome(int x) {
        Stack<Character> stack = new Stack<Character>();
        String s = String.valueOf(x);
        List<Character> list = s.chars().mapToObj(c -> (char) c).collect(Collectors.toList());
        for (int i = 0; i < list.size(); i++) {
            if (i<list.size()/2){
                stack.push(list.get(i));
            }else if (i == list.size()/2){
                if (list.size()%2==0){
                    Character pop = stack.pop();
                    if (pop != list.get(i)){
                        return false;
                    }
                }
            }else {
                Character pop = stack.pop();
                if (pop != list.get(i)){
                    return false;
                }
            }
        }
        return true;
    }
}
